package com.broadengate.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.broadengate.form.PasswordChangeForm;
import com.broadengate.model.Card;
import com.broadengate.service.CardService;
import com.broadengate.service.PasswordChangeService;

public class PasswordChangeAction extends DispatchAction {

	private PasswordChangeService passwordChangeService;
	private CardService cardService;

	/******
	 * 实现用户修改密码
	 * 核心功能由调用passwordChangeService对象的方法pswChanged()实现
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward 对象
	 */
	public ActionForward passwordChange(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		   System.out.println("PasswordChangeAction进入");
		   HttpSession session=request.getSession();
		   String a= request.getSession().getAttribute("cardNO").toString();
		  // String a=request.getParameter("cardNO");
		   PasswordChangeForm passwordChangeForm = (PasswordChangeForm) form;						
			Card cardX=cardService.findCardByCardNO(a);
			String newPSW=passwordChangeForm.getNpassword();
			cardX.setPassword(newPSW);
			
			try {
				passwordChangeService.pswChanged(cardX);
				 session.setAttribute("psw",newPSW);
				return mapping.findForward("success");
			} catch (Exception e) {
				e.printStackTrace();
				return mapping.findForward("fail");
			}
			
	}

	public PasswordChangeService getPasswordChangeService() {
		return passwordChangeService;
	}

	public void setPasswordChangeService(PasswordChangeService passwordChangeService) {
		this.passwordChangeService = passwordChangeService;
	}

	public CardService getCardService() {
		return cardService;
	}

	public void setCardService(CardService cardService) {
		this.cardService = cardService;
	}

	}



